package com.anXin.article.controller;


import com.anXin.article.mapper.ArticleMapper;
import com.anXin.article.service.ArticleService;
import com.anXin.article.service.CollectService;
import com.anXin.article.service.LikeService;
import com.anXin.model.article.pojos.Article;
import com.anXin.model.article.pojos.ArticleChannel;
import com.anXin.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/app/article")
public class ArticleController {

    @Resource
    private ArticleService articleService;
    @Resource
    private ArticleMapper articleMapper;


    @Resource
    private CollectService collectService;

    @Resource
    private LikeService likeService;




    @GetMapping("/selectMyArticle")
    public ResponseResult<List<Article>> selectMyArticle() {
        return articleService.selectMyArticle();
    }

    @GetMapping("/selectMyArticleToBeReviewed")
    public ResponseResult<List<Article>> selectMyArticleToBeReviewed() {
        return articleService.selectMyArticleToBeReviewed();
    }

    @GetMapping("/selectMyArticleByAudited")
    public ResponseResult<List<Article>> selectMyArticleByAudited() {
        return articleService.selectMyArticleByAudited();
    }

    @GetMapping("/selectMyArticleByUnPublish")
    public ResponseResult<List<Article>> selectMyArticleByUnPublish() {
        return articleService.selectMyArticleByUnPublish();
    }

    @GetMapping("/selectMyArticleByReleased")
    public ResponseResult<List<Article>> selectMyArticleByReleased() {
        return articleService.selectMyArticleByReleased();
    }
    /**
     * 全部查询：进入界面自动加载
     */


    @GetMapping("/selectAllArticle")
    public ResponseResult<List<Article>> selectAllArticle() {
        return articleService.selectAllArticle();
    }

    /**
     * 按文章频道查询
     */

    @GetMapping("/selectArticleByChannel/{id}")
    public ResponseResult<List<Article>> selectArticleByChannel(@PathVariable Long id) {
        return articleService.selectArticleByChannel(id);
    }

    /**
     * 博客详情
     */

    @GetMapping("/articleDetail/{id}")
    public ResponseResult<Article> articleDetail(@PathVariable("id") Long id) {
        Article article = articleMapper.selectById(id);
        article.setLikeCount(likeService.likeCount(article.getId()));
        article.setCollectionCount(collectService.collectCount(article.getId()));
        article.setIsLike(likeService.isLike(article.getId()));
        article.setIsCollection(collectService.isCollect(article.getId()));
        return ResponseResult.okResult(article);
    }

    @GetMapping("/channel/list")
    public ResponseResult<List<ArticleChannel>> ListChannel(){
       return articleService.selectChannel();
    }
}
